import { sendSmsRequest } from "@/services/ali-dysmsapi-client";
import { createRandomNumber } from "@/utils/random";
import { Request, Response, NextFunction } from "express";

interface Params {
	phone_number: string;
}
export default async (request: Request, response: Response, next: NextFunction) => {
	try {
		const params = request.body as unknown as Params;
		const verification_code = createRandomNumber(6);
		await sendSmsRequest({
			signName: "北京博雅国际",
			templateCode: "SMS_307091256",
			phoneNumbers: params.phone_number,
			templateParam: JSON.stringify({ code: verification_code }),
		});
		response.json({ data: { verification_code }, message: "成功" });
	} catch (error) {
		response.statusCode = 400;
		next(error);
	}
};
